$(function () {

    $("#datas").load(base + "/student/list");

    $("#addstudent").submit(function (event) {
        event.preventDefault();// 阻止元素发生默认的行为
        $.ajax({
            url: "add",
            type: "POST",
            data: $(this).serialize(),
            success: function (data) {
                if (data == 1) {
                    window.location.href = base + "/student/index";
                } else {
                    $("#loginHint").html("<b>学号重复!</b>");
                }
            }
        });
    });

    $("#login-form").submit(function (event) {
        event.preventDefault();// 阻止元素发生默认的行为
// Jquery发送AJAX请求
        $.ajax({
            url: "student/login",
            type: "POST",
            data: $(this).serialize(),
            success: function (data) {
                // alert(data);
                if (data == 1) {
                    // 说明登录成功,则跳转页面
                    window.location.href = base + "/student/index";
                } else {
                    // 说明登录失败,显示提示
                    $("#loginHint").html("<b>用户名或者密码错误!</b>");
                    $("#login_form").removeClass('shake_effect');
                    setTimeout(function () {
                        $("#login_form").addClass('shake_effect')
                    }, 1);
                }
            }
        });
    });

    /*$("#edit").submit(function (event) {
        event.preventDefault();// 阻止元素发生默认的行为
        $.ajax({
            url: "edit",
            type: "POST",
            data: $(this).serialize(),
            success: function (data) {
                if (data == 1) {
                    window.location.href = base + "/student/index";
                }
            }
        });
    });*/

    $(".btn").click(function(){
        //alert( $("#search").val())
        $(".dd").load(base+"/student/search?name="+ $("#search").val());
        $("#datas").hide()


    });

    $(".register-form").click(function () {
        $("#datas").toggle();
    })
});


function logout() {
    var r = confirm("确定退出？");
    if (r) {
        window.location.href = base + "/student/logout";
    }
}


function add() {
    window.location.href = base + "/student/preAdd";
}

function go(pageNow) {
    //window.location.href= base + "/permission/product/list?pageNow=" + pageNow;

    $("#datas").load(base + "/student/list?pageNum=" + pageNow);
}

function goname(pageNow) {
    //window.location.href= base + "/permission/product/list?pageNow=" + pageNow;

    // $("#dd").load(base + "/student/search?namepageNum=" + pageNow);
    $(".dd").load(base+"/student/search?name="+ $("#search").val()+"&pageNum=" + pageNow);
}

// 跳转修改页面
function editStudent(id) {
    window.location.href = base + "/student/preEdit?id=" + id;
}

function deleteStudent(id) {
    var r = confirm("确定要删除吗?");
    if (r) {
        // JS页面跳转
        window.location.href = base + "/student/delete?id=" + id;
    }
}

function showDetial(id) {
    window.location.href = base + "/student/showDetail?id=" + id;
}

function search(name) {
    window.location.href = base + "/student/preSearch/" + name;
}

function back() {
    window.location.href = base + "/student/back";
}